package com.da.javatest.thread.juc.threadlocal;

/**
 * @author chenlida
 * @date 2020/9/4 14:18
 * @description: 使用InheritableThreadLocal可以实现多个线程访问ThreadLocal的值，我们在主线程中创建一个InheritableThreadLocal的实例，
 * 然后在子线程中得到这个InheritableThreadLocal实例设置的值。
 */
public class InheritableThreadLocal1 {
    private static ThreadLocal<String> threadLocal1 = new InheritableThreadLocal<>();
    private static ThreadLocal<String> threadLocal2 = new ThreadLocal<>();

    public static void main(String[] args) {
        threadLocal1.set("好菜");
        threadLocal2.set("好菜");
        new Thread(() -> System.out.println("达少菜吗？" + threadLocal1.get())).start();
        new Thread(() -> System.out.println("达少菜吗？" + threadLocal2.get())).start();
    }
}
